<?require_once("connection.php");
  //include("WP-ROOT-PATH/wp-config.php");
  //$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  //include_once('connect_to_db.php');
  //error_reporting(0);
?>

  <div style="margin-left:300px;font-size:18;font-familyt:Arial">Courses</div><br>
  <a href="#" style="text-decoration:none;font-size:12;font-colour:blue" onclick="add_course(0,0);return false;">
      Add new course
  </a>
  OR
  <?
    $query = "select * from g_courses;";
    $result = @mysql_query($query);
    //global $wpdb;
    //echo $wpdb;
    //$result = $wpdb->get_results($query);
    //foreach($result as $course){
    //  echo $course->name."<br>";
    //}
    
    //_e('Database', FB_ADM_TEXTDOMAIN);
	//echo DB_NAME;
    //while($row=mysql_fetch_array($result)){
    //  echo $row["name"]." ";
    //}

    //exit;
    //echo $_SESSION["maxat"];

    echo "<select id='copy_course'>";
    echo "<option value='0' selected>Choose</option>";
    while($row=@mysql_fetch_array($result))
        echo "<option value='".$row["course_id"]."'>".$row["name"]." - ".$row["year"]." ".$row["semester"]."</option>";
    echo "</select>";
    if(mysql_num_rows($result)>0)
        echo "<button onclick='copy_course();'>Copy</button>";
    else
        echo "<button disabled>Copy</button>";
    echo "<br><br>";
  ?>



  <?
    //if($_GET["person_id"])
    //  $person_id = $_GET["person_id"];
    /*
	if($_GET["order_by"]>0){
	  if($person_id==0){
	    if($_GET["count"]==1)
	      $query = "select t1.*, t2.personName, t3.groupName from verse t1, person t2, groups t3 where t1.personID=t2.personID and t1.groupID=t3.groupID order by ".$_GET["order_by"].";";
	    else
	      if($_GET["count"]==0)
	        $query = "select t1.*, t2.personName, t3.groupName from verse t1, person t2, groups t3 where t1.personID=t2.personID and t1.groupID=t3.groupID order by ".$_GET["order_by"]." DESC;";
	  }
	  else{
	    if($_GET["count"]==1)
	      $query = "select t1.*, t2.personName, t3.groupName from verse t1, person t2, groups t3 where t1.personID=t2.personID and t1.groupID=t3.groupID and t1.personID=".$person_id." order by ".$_GET["order_by"].";";
	    else
	      if($_GET["count"]==0)
	        $query = "select t1.*, t2.personName, t3.groupName from verse t1, person t2, groups t3 where t1.personID=t2.personID and t1.groupID=t3.groupID and t1.personID=".$person_id." order by ".$_GET["order_by"]." DESC;";
	  }
	}
	else{
	  if($person_id==0)
	    $query = "select t1.*, t2.personName, t3.groupName from verse t1, person t2, groups t3 where t1.personID=t2.personID and t1.groupID=t3.groupID order by t1.verseSubject;";
	  else
	    $query = "select t1.*, t2.personName, t3.groupName from verse t1, person t2, groups t3 where t1.personID=t2.personID and t1.groupID=t3.groupID and t1.personID=".$person_id." order by t1.verseSubject;";
	}
	$result = @mysql_query($query, $connection);

	//echo mysql_error()."<br>";

	echo "Саны: ".mysql_num_rows($result);
    */
    //$connection = @mysql_pconnect("localhost","root","") or die("Could not connect to the server.");
    //$db = @mysql_select_db("web-eng-7",$connection) or die("Could not select database.");
    
    if(isset($_POST["course_name"]))
      $course_name=$_POST["course_name"];
    else
      $course_name="";
      
    $query = "select * from g_courses group by name;";
    $result = @mysql_query($query);

	    echo "<select id='course' onchange='c_c_change(this);return false;'>";
	    if($course_name=="")
	      echo "<option value='' selected>All Courses</option>";
	    else
          echo "<option value=''>All Courses</option>";
	    while($row=@mysql_fetch_array($result)){
          if($course_name==$row["name"]){
            echo "<option value='".$row["name"]."' selected>".$row["name"]."</option>";
            //$course_name = $row["name"];
          }
          else
            echo "<option value='".$row["name"]."'>".$row["name"]."</option>";
	    }
	    echo "</select>";

    if($course_name!="")
      $query = "select * from g_courses where name='".$course_name."';";
    else
      $query = "select * from g_courses;";
    $result = @mysql_query($query);
    $row_number = @mysql_num_rows($result);

    //global $wpdb;
    //echo $wpdb;
    //$results = $wpdb->get_results("SELECT course_id, name FROM m_courses");
    echo " Rows: ".$row_number;

      /*foreach($results as $result){
        echo "<div id='course".$result->course_id."' style='display:block;margin-left:40px'>
               <div>Lectures</div>
               <div>Exercises</div>
             </div>";
      } */
    if($row_number>0){
	    echo "<table class='tbl_2'><tbody>";
	    echo "<tr class='inside'>";
	    echo "<th>&nbsp;</th>";
	    echo "<th>&nbsp;</th>";
	    echo "<th><a href='#' onclick='return false;display_table(1,1);return false;'>course_id</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(1,2);return false;'>name</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(1,3);return false;'>semester</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(1,4);return false;'>content</a></th>";
	    echo "</tr>";
	    while($row = @mysql_fetch_array($result)){
	        //echo "<tr class='inside' id='OnMouseTr".$row[0]."' style='background:#EAF7EB' onmouseover='mouse_over(".$row[0].");return false;' onmouseout='mouse_out(".$row[0].");return false;'>";
	        echo "<tr class='inside' id='OnMouseTr".$row[0]."' style='background:#EAF7EB' >";
	        echo "<td><a href='#' id='".$row[0]."' onclick='delete_course(".$row[0]."); return false;'><img border='0' alt='Delete' src='../wp-content/plugins/course_management/images/delete.png'/></a></td>";
	        echo "<td><a href='#' id='".$row[0]."' onclick='add_course(1,".$row[0]."); return false;'><img border='0' alt='Edit' src='../wp-content/plugins/course_management/images/edit.png'/></a></td>";
            echo "<td>".$row["course_id"]."</td>";
	        echo "<td>".$row["name"]."</td>";
	        echo "<td>".$row["year"]." ".$row["semester"]."</td>";
	        echo "<td>".$row["content"]."</td>";
	        echo "</tr>";
	    }
	echo "</tbody></table>";
	}
	else{
        die("<br>There are no courses!!!");
        exit;
	}
  ?>
